/**
 * @author 徐楠
 * @date 2022/5/16 9:47
 * @version 1.0
 */

package com.xunan.likou;

import java.util.*;

public class HanoiTowerProblem {
    public static void main(String[] args) {
        List<Integer> A = new ArrayList<>();
        A.add(2);
        A.add(1);
        A.add(0);
        List<Integer> B = new ArrayList<>();
        List<Integer> C = new ArrayList<>();
        System.out.println("start ");
        hanota(A, B, C);

    }

    public static void hanota(List<Integer> A, List<Integer> B, List<Integer> C) {
        movePlate(A.size(), A, B, C);
    }

    public static void movePlate(int n, List<Integer> start, List<Integer> temp, List<Integer> target) {
        if (n == 1) {
            move(start, target);
            return;
        }
        //将target看作中间柱子，将n-1个碟子从start移动到temp
        movePlate(n - 1, start, target, temp);
        move(start, target);
        //将start看作中间柱子，将n-1个碟子从temp移动到target
        movePlate(n - 1, temp, start, target);
    }

    public static void move(List<Integer> from, List<Integer> to) {
        Integer temp = from.remove(from.size() - 1);
        to.add(temp);
        System.out.println("将" + temp + "号盘子从 "  + " " + from + " 移动到 " + " " + to);
    }


}
